package lock.countDownLatch.hospital;

import java.util.concurrent.CountDownLatch;

/**
 * 取药任务
 */
public class QuYaoTask implements Runnable {

    private CountDownLatch countDownLatch;

    public QuYaoTask(CountDownLatch countDownLatch) {
        this.countDownLatch = countDownLatch;
    }

    public void run() {
        System.out.println("开始排队取药。。。");
        try {
            // 模拟耗时操作
            Thread.sleep(10000);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            // 任务执行完成后，锁的计数器减1
            countDownLatch.countDown();
            System.out.println("取药完成后计数器为：" + countDownLatch.getCount());
        }
    }

}
